import {fhirServerApi} from "../../api/modules/fhirApi";

const app = require('@/lib/app');

export default {
  state: {
    // 应用信息
    appId: app.appId,
    appName: app.appName,
    appVersion: app.appVersion,
    // 公司信息
    copyName: app.copyName,
    copyRight: app.copyRight,
    copyContact: app.copyContact,
    activeName: '',
    openOptions: [{name: 'home', resourceName: '首页', path: '/home'}],
    currentPath: [],
    fhirServer: 'http://hapi.fhir.org/baseR4',
    mediaType: 'json',
    menuData: [
      {
        "id": 1,
        "children": [],
        "parentId": 0,
        "resourceName": "患者",
        "viewUrl": "/patient",
        "icon": null
      },
      {
        "id": 8,
        "children": [],
        "parentId": 0,
        "resourceName": "预约",
        "viewUrl": "/appointment",
        "icon": null
      },
      {
        "id": 2,
        "children": [],
        "parentId": 0,
        "viewUrl": "/enc",
        "resourceName": "就诊",
        "icon": null
      },
      {
        "id": 7,
        "children": [],
        "parentId": 0,
        "viewUrl": "/medication",
        "resourceName": "医嘱",
        "icon": null
      },
      {
        "id": 9,
        "children": [],
        "parentId": 0,
        "viewUrl": "/procedure",
        "resourceName": "手术",
        "icon": null
      },
      {
        "id": 10,
        "children": [],
        "parentId": 0,
        "viewUrl": "/codeSystem",
        "resourceName": "术语",
        "icon": null
      },
      {
        "id": 3,
        "children": [],
        "parentId": 0,
        "resourceName": "检查申请",
        "viewUrl": "/request",
        "icon": null
      },
      {
        "id": 4,
        "children": [],
        "parentId": 0,
        "resourceName": "检查报告",
        "viewUrl": "/preport",
        "icon": null
      },
      {
        "id": 5,
        "children": [],
        "parentId": 0,
        "resourceName": "检验报告",
        "viewUrl": "/labreport",
        "icon": null
      },
      {
        "id": 6,
        "children": [],
        "parentId": 0,
        "resourceName": "区域文档",
        "viewUrl": "/bundle",
        "icon": null
      },
    ]
  },
  mutations: {
    setActiveMenu: (state, data) => {
      state.activeName = data.name;

      let ex = false;
      for (let option of state.openOptions) {
        if (option.name === data.name) {
          ex = true;
          break;
        }
      }
      if (!ex) {
        state.openOptions.push(data);
      }
    },
    // 删除tabs
    deleteTabs: (state, name) => {
      let index = 0;
      for (let option of state.openOptions) {
        if (option.name === name) {
          break;
        }
        index++;
      }
      state.openOptions.splice(index, 1);
    },
    initServer(state,params){
      state.fhirServer = params.fhirServer;
      fhirServerApi({server:params.fhirServer});
    }
  },
  actions: {}
}
